<?php
    if (!defined('EXPONENT')) exit('');
    if (exponent_users_isAdmin() ||  exponent_permissions_check(array("administrate"),$loc))
    {
        $template=new template("mailsystemmodule","chart_test",$loc); 
        /*
        * by date
        * by time 
        */
        if($_REQUEST['timeby']=="hour")
        {
            $sql="SELECT COUNT( * ) as count , FROM_UNIXTIME( date_insert,'%Y-%m-%d %H:%i:%s' ) as date FROM {$db->prefix}mailsystem_mail GROUP BY HOUR(  FROM_UNIXTIME( date_insert,'%Y %D %M %h' )  ) ";
        }
        else        
        $sql="SELECT COUNT( * ) as count , DATE( FROM_UNIXTIME( date_insert ) ) as date FROM {$db->prefix}mailsystem_mail GROUP BY DATE( FROM_UNIXTIME( date_insert ) ) ";
$mail=$db->selectObjectsBySql($sql);
$chart=null;
foreach($mail as $k=>$v)
{    
   //$v->time=strtotime($v->date).'000';
    $chart[$k][0]=$v->date;
    $chart[$k][1]=$v->count;
}
        
        $template->assign('chart',json_encode($chart));
        $template->assign('mails',$mail);
        $template->output();       
    }


?>
